﻿using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using ZY.EntityFrameWork.Core.DBHelper;

namespace EF_CodeFist
{
    public class ServiceCaller
    {
        private static ServiceCaller instance = new ServiceCaller();
        //private IUnityContainer container;

        private bool isWcf = false;
        public static ServiceCaller Instance
        {
            get { return instance; }
        }
       
        private ServiceCaller()
        {
            //是否调用WCF可以写在配置文件中
            //同一接口注册多个类，解析时按后注册的来，也可注册时指定名称
            bool config = true;
            //UnityHelper.Instance.RegisterType<IArvOPService, LocalArvOpService>("Local");
            if (config)
            {
                //container = new UnityContainer();
                isWcf = true;
                
            }
        }

        public T GetService<T>()
        {
            if (isWcf)//如果是WCF调用方式
            {
                return UnityHelper.Instance.Resolve<T>("Wcf");
            }
            else
            {
                return UnityHelper.Instance.Resolve<T>("Local");
            }
        }
    }
}
